* project: Ghana school feeding  - Learning paper
* EA, 19 March 2020
* this do-file provides the codes for the main results provided in the paper

global who  "melino"
**** Betta BS
if "$who"=="betta bs" {
		global output "C:/Users/eaurino/Dropbox/ghana/output"
		
		}
*** Melino
if "$who"=="melino" {
		global output "/Users/betta/Dropbox/ghana/output"
		
		}
			
	************** TABLE 4a. Treatment effects for the whole sample with romano-wolf adjusted p-values
	
	* First generate dataset for romano wolf: i need one stacked dataset with one row for each child & outcome @ endline and the corresponding baseline value of test scores, otherwise the rw command does not work
	
	use "$output/combined_data.dta", clear
	
	drop if child_panel ==0
	keep u_id child_panel zmaths zlit zraven zdigit learn_ind cog_ind all_index arm2 wave region locid male north poor_r1 missing_* enrol grade rep_grade primary days_attend exp_edu tot_fees food_transp books_exp extra_tuition cost_food
		
	reshape wide child_panel zmaths zlit zraven zdigit learn_ind cog_ind all_index arm2 region primary days_attend grade enrol rep_grade /// 
		locid male north poor_r1 missing_* exp_edu tot_fees food_transp books_exp extra_tuition cost_food, i(u_id) j(wave)
	
	tempfile base
	save `base'
	
		keep u_id locid0 region0 arm20 zmaths0 zmaths1 male1 poor_r10 north1 missing_math0
		gen baseline=zmaths0
	tempfile maths 
	save `maths'
	
	use `base'
		keep u_id locid0 region0 arm20 zlit0 zlit1 male1 poor_r10 north1 missing_zlit10 
		gen baseline=zlit0
	tempfile lit
	save `lit'
	
	use `base'
		keep u_id locid0 region0 arm20 zraven0 zraven1 male1 poor_r10 north1 missing_zraven10
		gen baseline=zraven0
	tempfile raven
	save `raven'
	
	use `base'
		keep u_id locid0 region0 arm20 zdigit0 zdigit1 male1 poor_r10 north1 missing_zdigit10
		gen baseline=zdigit0
	tempfile digit
	save `digit'
	
	use `base'
		keep u_id locid0 region0 arm20 learn_ind1 learn_ind0 male1 poor_r10 north1 missing_math0 missing_zlit10  
		gen baseline=learn_ind0
	tempfile learn
	save `learn'	
	
	use `base'
		keep u_id locid0 region0 arm20 cog_ind1 cog_ind0 male1 poor_r10 north1 missing_zraven10 missing_zdigit10 
		gen baseline=cog_ind0
	tempfile cog
	save `cog'	
	
	use `base'
		keep u_id locid0 region0 arm20 all_index1 all_index0 male1 poor_r10 north1 missing_math0 missing_zlit10 missing_zraven10 missing_zdigit10 
		gen baseline=all_index0
	tempfile all
	save `all'	
	
	use `base'
		keep u_id locid0 region0 arm20 all_index1 all_index0 male1 poor_r10 north1 enrol1 enrol0 
		gen baseline = enrol0
	tempfile enrol
	save `enrol'
	
	use `base'
		keep u_id locid0 region0 arm20 all_index1 all_index0 male1 poor_r10 north1 grade1 grade0 
		gen baseline = grade0
	tempfile grade
	save `grade'
	
	use `base'
		keep u_id locid0 region0 arm20 all_index1 all_index0 male1 poor_r10 north1 days_attend1 days_attend0 
		gen baseline = days_attend0
	tempfile attend
	save `attend'
	
	use `base'
		keep u_id locid0 region0 arm20 all_index1 all_index0 male1 poor_r10 north1 rep_grade1 rep_grade0 
		gen baseline = rep_grade0
	tempfile rep_grade
	save `rep_grade'

		
	use `maths'
	append using `lit'
	append using `raven'
	append using `digit'
	append using `learn'
	append using `cog'
	append using `all'
	append using `enrol'
	append using `grade'
	append using `attend'
	append using `rep_grade'
	
	
	sort u_id
	
	save "$output/data_rw.dta", replace
	asasa

**** I can now move on to calculate treatment effects for all children 
	
	use "$output/data_rw.dta", clear
	rwolf zmaths1 zlit1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid) 

	local doit "replace"
	local doit2 "append"
	
	sum zmaths1 if arm20==1 
	local MmathT=r(mean)
	sum zmaths1 if arm20==0 
	local MmathC=r(mean)
	
	sum zlit1 if arm20==1 
	local MlitT=r(mean)
	sum zlit1 if arm20==0 
	local MlitC=r(mean)
	
	sum learn_ind1 if arm20==1 
	local MlearnT=r(mean)
	sum learn_ind1 if arm20==0 
	local MlearnC=r(mean)
	
	local rw_math=e(rw_zmaths1)
	local rw_lit=e(rw_zlit1)

	reg zmaths1 zmaths0 arm20 i.region0, vce(cluster locid) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MmathT', Mean Control, `MmathC', R-W p-value, `rw_math') ctitle("Maths") keep(arm20)
		
	reg zlit1 zlit0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast   dec(3) bdec(3) addstat(Mean Treatment, `MlitT', Mean Control, `MlitC', R-W p-value, `rw_lit') ctitle("Literacy") keep(arm20)

	reg learn_ind1 learn_ind0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  dec(3) bdec(3) addstat(Mean Treatment, `MlearnT', Mean Control, `MlearnC') ctitle("Composite: maths and literacy") keep(arm20)
	
	** now rerun the same regressions to add the confidence intervals 
	
	reg zmaths1 zmaths0 arm20 i.region0 , vce(cluster locid) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) addstat(Mean Treatment, `MmathT', Mean Control, `MmathC', R-W p-value, `rw_math') ctitle("Maths") keep(arm20)
	
	reg zlit1 zlit0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) addstat(Mean Treatment, `MlitT', Mean Control, `MlitC', R-W p-value, `rw_lit') ctitle("Literacy") keep(arm20)

	reg learn_ind1 learn_ind0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) addstat(Mean Treatment, `MlearnT', Mean Control, `MlearnC') ctitle("Composite: maths and literacy") keep(arm20)
	
	* stratified models * (panels b,c, and d of Table 4)
	
	********************************* Gender **********************************************
	
	use "$output/data_rw.dta", clear
	
	* gen girl dummy
	gen girl=1 if male1==0
		replace girl =0 if male1==1

	* girls
	rwolf zmaths1 zlit1 if girl ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum zmaths1 if arm20==1 & girl==1 
	local MmathTg=r(mean)
	sum zmaths1 if arm20==0 & girl==1 
	local MmathCg=r(mean)
	sum zmaths1 if arm20==1 & girl==0 
	local MmathTb=r(mean)
	sum zmaths1 if arm20==0 & girl==0 
	local MmathCb=r(mean)
	
	sum zlit1 if arm20==1 & girl==1 
	local MlitTg=r(mean)
	sum zlit1 if arm20==0 & girl==1 
	local MlitCg=r(mean)
	sum zlit1 if arm20==1 & girl==0 
	local MlitTb=r(mean)
	sum zlit1 if arm20==0 & girl==0 
	local MlitCb=r(mean)
	
	sum learn_ind1 if arm20==1 & girl==1 
	local MlearnTg=r(mean)
	sum learn_ind1 if arm20==0 & girl==1 
	local MlearnCg=r(mean)
	sum learn_ind1 if arm20==1 & girl==0 
	local MlearnTb=r(mean)
	sum learn_ind1 if arm20==0 & girl==0 
	local MlearnCb=r(mean)
	
	local rw_math_girl=e(rw_zmaths1)
	local rw_lit_girl=e(rw_zlit1)
	
	* boys
	rwolf zmaths1 zlit1 if girl ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_math_boy=e(rw_zmaths1)
	local rw_lit_boy=e(rw_zlit1)
	
	local doit "replace"
	local doit2 "append"
	
	* Maths * 
	reg zmaths1 zmaths0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("Girls maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_math_girl') keep(arm20)
		
	reg zmaths1 zmaths0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Boys maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_math_boy') keep(arm20)
		
	* now add the table with CIs
	 
	reg zmaths1 zmaths0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_math_girl') keep(arm20)
		
	reg zmaths1 zmaths0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_math_boy')  keep(arm20)
	
	* Literacy * 
	
	reg zlit1 zlit0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Girls lit") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_lit_girl') keep(arm20)
		
	reg zlit1 zlit0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Boys lit") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_lit_boy') keep(arm20)
		
	* now add the table with CIs
	 
	reg zlit1 zlit0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls lit") keep(arm20)
		
	reg zlit1 zlit0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys lit") keep(arm20)
	
	* learning composite *
	
	reg learn_ind1 learn_ind0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Girls learn") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg') keep(arm20)
		
	reg learn_ind1 learn_ind0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Boys learn") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb') keep(arm20)
		
	* now add the table with CIs
	 
	reg learn_ind1 learn_ind0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls learn") keep(arm20)
		
	reg learn_ind1 learn_ind0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys learn") keep(arm20)

	********************************* HH poverty **********************************************
	* poorest kids
	rwolf zmaths1 zlit1 if poor_r10 ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum zmaths1 if arm20==1 & poor_r10==1 
	local MmathTg=r(mean)
	sum zmaths1 if arm20==0 & poor_r10==1 
	local MmathCg=r(mean)
	sum zmaths1 if arm20==1 & poor_r10==0 
	local MmathTb=r(mean) 
	sum zmaths1 if arm20==0 & poor_r10==0 
	local MmathCb=r(mean)
	
	sum zlit1 if arm20==1 & poor_r10==1 
	local MlitTg=r(mean)
	sum zlit1 if arm20==0 & poor_r10==1 
	local MlitCg=r(mean)
	sum zlit1 if arm20==1 & poor_r10==0 
	local MlitTb=r(mean)
	sum zlit1 if arm20==0 & poor_r10==0 
	local MlitCb=r(mean)
	
	sum learn_ind1 if arm20==1 & poor_r10==1 
	local MlearnTg=r(mean)
	sum learn_ind1 if arm20==0 & poor_r10==1 
	local MlearnCg=r(mean)
	sum learn_ind1 if arm20==1 & poor_r10==0 
	local MlearnTb=r(mean)
	sum learn_ind1 if arm20==0 & poor_r10==0 
	local MlearnCb=r(mean)
	
	local rw_math_poor=e(rw_zmaths1)
	local rw_lit_poor=e(rw_zlit1)
	
	* richest
	rwolf zmaths1 zlit1 if poor_r10 ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_math_nonpoor=e(rw_zmaths1)
	local rw_lit_nonpoor=e(rw_zlit1)
	
	local doit "replace"
	local doit2 "append"
	
	* Maths * 
	reg zmaths1 zmaths0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("Poor maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_math_poor') keep(arm20)
		
	reg zmaths1 zmaths0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_math_nonpoor') keep(arm20)
		
	* now add the table with CIs
	 
	reg zmaths1 zmaths0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_math_poor') keep(arm20)
		
	reg zmaths1 zmaths0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_math_nonpoor')  keep(arm20)
	
	* Literacy * 
	
	reg zlit1 zlit0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor lit") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_lit_poor') keep(arm20)
		
	reg zlit1 zlit0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor lit") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_lit_nonpoor') keep(arm20)
		
	* now add the table with CIs
	 
	reg zlit1 zlit0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor lit") keep(arm20)
		
	reg zlit1 zlit0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor lit") keep(arm20)
	
	* learning composite *
	
	reg learn_ind1 learn_ind0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor learn") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg') keep(arm20)
		
	reg learn_ind1 learn_ind0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor learn") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb') keep(arm20)
		
	* now add the table with CIs
	 
	reg learn_ind1 learn_ind0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor learn") keep(arm20)
		
	reg learn_ind1 learn_ind0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor learn") keep(arm20)

	********************************* Place of Residence **********************************************
	
	* north
	rwolf zmaths1 zlit1 if north1==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 

	sum zmaths1 if arm20==1 & north1==1 
	local MmathTg=r(mean)
	sum zmaths1 if arm20==0 & north1==1 
	local MmathCg=r(mean)
	sum zmaths1 if arm20==1 & north1==0 
	local MmathTb=r(mean)
	sum zmaths1 if arm20==0 & north1==0 
	local MmathCb=r(mean)
	
	sum zlit1 if arm20==1 & north1==1 
	local MlitTg=r(mean)
	sum zlit1 if arm20==0 & north1==1 
	local MlitCg=r(mean)
	sum zlit1 if arm20==1 & north1==0 
	local MlitTb=r(mean)
	sum zlit1 if arm20==0 & north1==0 
	local MlitCb=r(mean)
	
	sum learn_ind1 if arm20==1 & north1==1 
	local MlearnTg=r(mean)
	sum learn_ind1 if arm20==0 & north1==1 
	local MlearnCg=r(mean)
	sum learn_ind1 if arm20==1 & north1==0 
	local MlearnTb=r(mean)
	sum learn_ind1 if arm20==0 & north1==0 
	local MlearnCb=r(mean)
	
	local rw_mathnorth=e(rw_zmaths1)
	local rw_litnorth=e(rw_zlit1)
	
	* south
	rwolf zmaths1 zlit1 if north1==0, indepvar(arm20) controls(i.region0 baseline  ) seed(7) reps(2000) vce(cluster locid0) 
	local rw_mathsouth=e(rw_zmaths1)
	local rw_litsouth=e(rw_zlit1)
	
	local doit "replace"
	local doit2 "append"
	
	* Maths * 
	reg zmaths1 zmaths0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("North maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_mathnorth') keep(arm20)
		
	reg zmaths1 zmaths0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_mathsouth') keep(arm20)
		
	* now add the table with CIs
	 
	reg zmaths1 zmaths0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_mathnorth') keep(arm20)
		
	reg zmaths1 zmaths0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_mathsouth')  keep(arm20)
	
	* Literacy * 
	
	reg zlit1 zlit0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North lit") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_litnorth') keep(arm20)
		
	reg zlit1 zlit0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South lit") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_litsouth') keep(arm20)
		
	* now add the table with CIs
	 
	reg zlit1 zlit0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North lit") keep(arm20)
		
	reg zlit1 zlit0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South lit") keep(arm20)
	
	* learning composite *
	
	reg learn_ind1 learn_ind0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North learn") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg') keep(arm20)
		
	reg learn_ind1 learn_ind0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South learn") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb') keep(arm20)
		
	* now add the table with CIs
	 
	reg learn_ind1 learn_ind0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North learn") keep(arm20)
		
	reg learn_ind1 learn_ind0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South learn") keep(arm20)
	
	
**** Table 4b treatment effects with diff in diff - march 2020 add romano wolf

use "$output/combined_data.dta", clear
/* old 
drop if child_panel ==0
	preserve
	keep if north ==1 
	*keep if male==0
	*keep if poor_r1==1
	xi: reg zmaths  wave##arm2 i.region   , cluster(locid) 
	est sto h1
	
	xi: reg zlit  wave##arm2  i.region  , cluster(locid) 
	est sto h2
	
	xi: reg learn_ind  wave##arm2  i.region  , cluster(locid) 
	est sto h3
	
	outreg2 [h*] using "$output/in_single3.xls", replace dec(3) stats(coef se) label ///
			drop(0b.wave#0b.arm2 0b.wave#1o.arm2 1o.wave#0b.arm2) sortvar(1.wave#1.arm2) 
	restore
*/
* all kids
rwolf zmaths zlit, indepvar(treatment) controls(arm2 i.region wave1) seed(7) reps(2000) vce(cluster locid) 

local doit "replace"
	local doit2 "append"
	
	sum zmaths if arm2==1 & wave==1
	local MmathT=r(mean)
	sum zmaths if arm2==0 & wave==1
	local MmathC=r(mean)
	
	sum zlit if arm2==1 & wave==1
	local MlitT=r(mean)
	sum zlit if arm2==0 & wave==1
	local MlitC=r(mean)
	
	sum learn_ind if arm2==1 & wave==1
	local MlearnT=r(mean)
	sum learn_ind if arm2==0 & wave==1
	local MlearnC=r(mean)
	
	local rw_math=e(rw_zmaths)
	local rw_lit=e(rw_zlit)

	xi: reg zmaths wave1 arm2 treatment i.region, cluster(locid)
	outreg2 using rank_m.xls, `doit' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MmathT', Mean Control, `MmathC', R-W p-value, `rw_math') ctitle("Maths") keep(treatment)
		
	xi: reg zlit wave1 arm2 treatment i.region, cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast   dec(3) bdec(3) addstat(Mean Treatment, `MlitT', Mean Control, `MlitC', R-W p-value, `rw_lit') ctitle("Literacy") keep(treatment)

	xi: reg learn_ind wave1 arm2 treatment i.region, cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  dec(3) bdec(3) addstat(Mean Treatment, `MlearnT', Mean Control, `MlearnC') ctitle("Composite: maths and literacy") keep(treatment)
	
	** now rerun the same regressions to add the confidence intervals 
	
	xi: reg zmaths wave1 arm2 treatment i.region, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Maths") keep(treatment)
	
	xi: reg zlit wave1 arm2 treatment i.region, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Literacy") keep(treatment)

	xi: reg learn_ind wave1 arm2 treatment i.region, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Composite: maths and literacy") keep(treatment)
	
		********************************* Gender **********************************************
	
	* gen girl dummy
	gen girl=1 if male==0
		replace girl =0 if male==1

	* girls
	rwolf zmaths zlit if girl ==1, indepvar(treatment) controls(arm2 i.region wave1) seed(7) reps(2000) vce(cluster locid) 
	
	sum zmaths if arm2==1 & wave==1 & girl==1
	local MmathTg=r(mean)
	sum zmaths if arm2==0 & wave==1 & girl==1
	local MmathCg=r(mean)
	sum zmaths if arm2==1 & wave==1 & girl==0
	local MmathTb=r(mean)
	sum zmaths if arm2==0 & wave==1 & girl==0
	local MmathCb=r(mean)
	
	sum zlit if arm2==1 & wave==1 & girl==1
	local MlitTg=r(mean)
	sum zlit if arm2==0 & wave==1 & girl==1
	local MlitCg=r(mean)
	sum zlit if arm2==1 & wave==1 & girl==0
	local MlitTb=r(mean)
	sum zlit if arm2==0 & wave==1 & girl==0
	local MlitCb=r(mean)
	
	sum learn_ind if arm2==1 & wave==1 & girl==1
	local MlearnTg=r(mean)
	sum learn_ind if arm2==0 & wave==1 & girl==1
	local MlearnCg=r(mean)
	sum learn_ind if arm2==1 & wave==1 & girl==0
	local MlearnTb=r(mean)
	sum learn_ind if arm2==0 & wave==1 & girl==0
	local MlearnCb=r(mean)
	
	local rw_math_girl=e(rw_zmaths)
	local rw_lit_girl=e(rw_zlit)
	
	* boys
	rwolf zmaths zlit if girl ==0, indepvar(treatment) controls(arm2 i.region wave1) seed(7) reps(2000) vce(cluster locid) 

	local rw_math_boy=e(rw_zmaths)
	local rw_lit_boy=e(rw_zlit)
	
	local doit "replace"
	local doit2 "append"
	
	* Maths * 
	xi: reg zmaths wave1 arm2 treatment i.region if girl ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_math_girl') ctitle("Girls maths") keep(treatment)
	
	xi: reg zmaths wave1 arm2 treatment i.region if girl ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_math_boy') ctitle("Boys maths") keep(treatment)
		
	* now add the table with CIs
	 
	xi: reg zmaths wave1 arm2 treatment i.region if girl ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls maths") keep(treatment)
	
xi: reg zmaths wave1 arm2 treatment i.region if girl ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys maths") keep(treatment)
	
	* Literacy * 
	
	xi: reg zlit wave1 arm2 treatment i.region if girl ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_lit_girl') ctitle("Girls lit") keep(treatment)
	
	xi: reg zlit wave1 arm2 treatment i.region if girl ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_lit_boy') ctitle("Boys lit") keep(treatment)
		
	* now add the table with CIs
	 
	xi: reg zlit wave1 arm2 treatment i.region if girl ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls lit") keep(treatment)
		
	xi: reg zlit wave1 arm2 treatment i.region if girl ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys lit") keep(treatment)
	
	* learning composite *
	xi: reg learn_ind wave1 arm2 treatment i.region if girl ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg') ctitle("Girls composite") keep(treatment)
	
	xi: reg learn_ind wave1 arm2 treatment i.region if girl ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast dec(3) bdec(3) addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb') ctitle("Boys composite") keep(treatment)
	
	* now add the table with CIs
	 
	xi: reg learn_ind wave1 arm2 treatment i.region if girl ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls learn") keep(treatment)
		
	xi: reg learn_ind wave1 arm2 treatment i.region if girl ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys learn") keep(treatment)

	********************************* HH poverty **********************************************
	* poorest kids
	rwolf zmaths zlit if poor_r1 ==1, indepvar(treatment) controls(arm2 i.region wave1) seed(7) reps(2000) vce(cluster locid) 

	sum zmaths if arm2==1 & poor_r1==1 & wave==1
	local MmathTg=r(mean)
	sum zmaths if arm2==0 & poor_r1==1 & wave==1
	local MmathCg=r(mean)
	sum zmaths if arm2==1 & poor_r1==0 & wave==1
	local MmathTb=r(mean) 
	sum zmaths if arm2==0 & poor_r1==0 & wave==1
	local MmathCb=r(mean)
	
	sum zlit if arm2==1 & poor_r1==1 & wave==1
	local MlitTg=r(mean)
	sum zlit if arm2==0 & poor_r1==1 & wave==1
	local MlitCg=r(mean)
	sum zlit if arm2==1 & poor_r1==0 & wave==1
	local MlitTb=r(mean)
	sum zlit if arm2==0 & poor_r1==0 & wave==1
	local MlitCb=r(mean)
	
	sum learn_ind if arm2==1 & poor_r1==1 & wave==1
	local MlearnTg=r(mean)
	sum learn_ind if arm2==0 & poor_r1==1 & wave==1
	local MlearnCg=r(mean)
	sum learn_ind if arm2==1 & poor_r1==0 & wave==1
	local MlearnTb=r(mean)
	sum learn_ind if arm2==0 & poor_r1==0 & wave==1
	local MlearnCb=r(mean)
	
	local rw_math_poor=e(rw_zmaths)
	local rw_lit_poor=e(rw_zlit)
	
	* richest
	rwolf zmaths zlit if poor_r1 ==0, indepvar(treatment) controls(arm2 i.region wave1) seed(7) reps(2000) vce(cluster locid) 

	local rw_math_nonpoor=e(rw_zmaths)
	local rw_lit_nonpoor=e(rw_zlit)
	
	local doit "replace"
	local doit2 "append"
	
	* Maths * 
	
	reg zmaths wave1 arm2 treatment i.region if poor_r1 ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("Poor maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_math_poor') keep(treatment)

	reg zmaths wave1 arm2 treatment i.region if poor_r1 ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_math_nonpoor') keep(treatment)
		
	* now add the table with CIs
	 
	reg zmaths wave1 arm2 treatment i.region if poor_r1 ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor maths") keep(treatment)
		
	reg zmaths wave1 arm2 treatment i.region if poor_r1 ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor maths") keep(treatment)
	
	* Literacy * 
	
	reg zlit wave1 arm2 treatment i.region if poor_r1 ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor lit") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_lit_poor') keep(treatment)
		
	reg zlit wave1 arm2 treatment i.region if poor_r1 ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor lit") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_lit_nonpoor') keep(treatment)
		
	* now add the table with CIs
	 
	reg zlit wave1 arm2 treatment i.region if poor_r1 ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor lit") keep(treatment)
		
	reg zlit wave1 arm2 treatment i.region if poor_r1 ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor lit") keep(treatment)
	
	* learning composite *
	reg learn_ind wave1 arm2 treatment i.region if poor_r1 ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor learn") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg') keep(treatment)
		
	reg learn_ind wave1 arm2 treatment i.region if poor_r1 ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor learn") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb') keep(treatment)
		
	* now add the table with CIs
	 
	reg learn_ind wave1 arm2 treatment i.region if poor_r1 ==1 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor learn") keep(treatment)
		
	reg learn_ind wave1 arm2 treatment i.region if poor_r1 ==0 , cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor learn") keep(treatment)


	********************************* Place of Residence **********************************************
	
	* north
	rwolf zmaths zlit if north==1, indepvar(treatment) controls(arm2 i.region wave1) seed(7) reps(2000) vce(cluster locid) 

	sum zmaths if arm2==1 & north==1 & wave==1
	local MmathTg=r(mean)
	sum zmaths if arm2==0 & north==1 & wave==1
	local MmathCg=r(mean)
	sum zmaths if arm2==1 & north==0 & wave==1
	local MmathTb=r(mean)
	sum zmaths if arm2==0 & north==0 & wave==1
	local MmathCb=r(mean)
	
	sum zlit if arm2==1 & north==1 & wave==1 
	local MlitTg=r(mean)
	sum zlit if arm2==0 & north==1 & wave==1
	local MlitCg=r(mean)
	sum zlit if arm2==1 & north==0 & wave==1
	local MlitTb=r(mean)
	sum zlit if arm2==0 & north==0 & wave==1
	local MlitCb=r(mean)
	
	sum learn_ind if arm2==1 & north==1 & wave==1 
	local MlearnTg=r(mean)
	sum learn_ind if arm2==0 & north==1 & wave==1
	local MlearnCg=r(mean)
	sum learn_ind if arm2==1 & north==0 & wave==1
	local MlearnTb=r(mean)
	sum learn_ind if arm2==0 & north==0 & wave==1
	local MlearnCb=r(mean)
	
	local rw_mathnorth=e(rw_zmaths)
	local rw_litnorth=e(rw_zlit)
	
	* south
	rwolf zmaths zlit if north==0, indepvar(treatment) controls(arm2 i.region wave1) seed(7) reps(2000) vce(cluster locid) 

	local rw_mathsouth=e(rw_zmaths)
	local rw_litsouth=e(rw_zlit)
	
	local doit "replace"
	local doit2 "append"
	
	* Maths * 
	xi: reg zmaths wave1 arm2 treatment i.region if north ==1, cluster(locid)
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("North maths") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_mathnorth') keep(treatment)
		
	xi: reg zmaths wave1 arm2 treatment i.region if north ==0, cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South maths") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_mathsouth') keep(treatment)
		
	* now add the table with CIs
	 
	xi: reg zmaths wave1 arm2 treatment i.region if north ==1, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North maths") keep(treatment)
		
	xi: reg zmaths wave1 arm2 treatment i.region if north ==0, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South maths") keep(treatment)
	
	* Literacy * 
	
	xi: reg zlit wave1 arm2 treatment i.region if north ==1, cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North lit") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_litnorth') keep(treatment)
		
	xi: reg zlit wave1 arm2 treatment i.region if north ==0, cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South lit") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_litsouth') keep(treatment)
		
	* now add the table with CIs
	 
	xi: reg zlit wave1 arm2 treatment i.region if north ==1, cluster(locid)	
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North lit") keep(treatment)
		
	xi: reg zlit wave1 arm2 treatment i.region if north ==0, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South lit") keep(treatment)
	
	* learning composite *
	
	xi: reg learn_ind wave1 arm2 treatment i.region if north ==1, cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North learn") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg') keep(treatment)
		
	xi: reg learn_ind wave1 arm2 treatment i.region if north ==0, cluster(locid)
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South learn") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb') keep(treatment)
		
	* now add the table with CIs
	 
	xi: reg learn_ind wave1 arm2 treatment i.region if north ==1, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North learn") keep(treatment)
		
	xi: reg learn_ind wave1 arm2 treatment i.region if north ==0, cluster(locid)
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South learn") keep(treatment)

	************* ANALYSIS OF MECHANISMS: SCHOOLING, COGNITION AND HUNGER ************************
	use "$output/data_rw.dta", clear
	
	*** Start by schooling (only do enrolment, attendance and attainment as per protocol) *** (TABLE 5)
	
	rwolf enrol1 days_attend1 grade1 , indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 

	local doit "replace"
	local doit2 "append"
	
	sum enrol1 if arm20==1 
	local MenrT=r(mean)
	sum enrol1 if arm20==0 
	local MenrC=r(mean)
	
	sum days_attend1 if arm20==1 
	local MdayT=r(mean)
	sum days_attend1 if arm20==0 
	local MdayC=r(mean)
	
	sum grade1 if arm20==1 
	local MgrT=r(mean)
	sum grade1 if arm20==0 
	local MgrC=r(mean)
	
	local rw_enr=e(rw_enrol1)
	local rw_day=e(rw_days_attend1)
	local rw_grade=e(rw_grade1)

	reg enrol1 enrol0 arm20 i.region0, vce(cluster locid) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast dec(3) bdec(3) ///
	addstat(Mean Treatment, `MenrT', Mean Control, `MenrC', R-W p-value, `rw_enr') ctitle("Enrolment") keep(arm20)
		
	reg days_attend1 days_attend0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast   dec(3) bdec(3) addstat(Mean Treatment, `MdayT', Mean Control, `MdayC', ///
	R-W p-value, `rw_day') ctitle("Attendance") keep(arm20)

	reg grade1 grade0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  dec(3) bdec(3) ///
	addstat(Mean Treatment, `MgrT', Mean Control, `MgrC', R-W p-value, `rw_grade') ctitle("Attainment") keep(arm20)
	
	** now rerun the same regressions to add the confidence intervals in order to do a table similar to the one by Attanasio et al paper
	
	reg enrol1 enrol0  arm20 i.region0 , vce(cluster locid) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Enrol") keep(arm20)
	
	reg days_attend1 days_attend0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Attendance") keep(arm20)

	reg grade1 grade0 arm20 i.region0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Attainment") keep(arm20)
	
	
	* Gender *
	
	use "$output/data_rw.dta", clear
	
	* gen girl dummy
	gen girl=1 if male1==0
		replace girl =0 if male1==1

	* girls
	rwolf enrol1 days_attend1 grade1 if girl ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum enrol1 if arm20==1 & girl==1 
	local MmathTg=r(mean)
	sum enrol1 if arm20==0 & girl==1 
	local MmathCg=r(mean)
	sum enrol1 if arm20==1 & girl==0 
	local MmathTb=r(mean)
	sum enrol1 if arm20==0 & girl==0 
	local MmathCb=r(mean)
	
	sum days_attend1 if arm20==1 & girl==1 
	local MlitTg=r(mean)
	sum days_attend1 if arm20==0 & girl==1 
	local MlitCg=r(mean)
	sum days_attend1 if arm20==1 & girl==0 
	local MlitTb=r(mean)
	sum days_attend1 if arm20==0 & girl==0 
	local MlitCb=r(mean)
	
	sum grade1 if arm20==1 & girl==1 
	local MlearnTg=r(mean)
	sum grade1 if arm20==0 & girl==1 
	local MlearnCg=r(mean)
	sum grade1 if arm20==1 & girl==0 
	local MlearnTb=r(mean)
	sum grade1 if arm20==0 & girl==0 
	local MlearnCb=r(mean)
	
	local rw_enr_girl=e(rw_enrol1)
	local rw_att_girl=e(rw_days_attend1)
	local rw_gr_girl=e(rw_grade1)
	
	* boys
	rwolf enrol1 days_attend1 grade1 if girl ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_enr_boy=e(rw_enrol1)
	local rw_att_boy=e(rw_days_attend1)
	local rw_gr_boy=e(rw_grade1)
		
	local doit "replace"
	local doit2 "append"
	
	* Enrolment *
	
	reg enrol1 enrol0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("Girls enrol") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_enr_girl') keep(arm20)
	
	reg enrol1 enrol0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls enrol") keep(arm20)
	
	reg enrol1 enrol0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Boys enrol") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_enr_boy') keep(arm20)
		
	reg enrol1 enrol0 arm20 i.region0 if girl ==0 , vce(cluster region) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys enrol") keep(arm20)
	
	* Attendance * 
	
	reg days_attend1 days_attend0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Girls attendance") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_att_girl') keep(arm20)
	
	reg days_attend1 days_attend0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls att") keep(arm20)
	
	reg days_attend1 days_attend0  arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Boys att") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_att_boy') keep(arm20)
		
	reg days_attend1 days_attend0  arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys lit") keep(arm20)
	
	* Attainment *
	
	reg grade1 grade0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Girls attain") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg', R-W p-value, `rw_gr_girl' ) keep(arm20)
	
	reg grade1 grade0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls attain") keep(arm20)
		
	reg grade1 grade0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Boys attain") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb', R-W p-value, `rw_gr_boy' ) keep(arm20) 
		
	reg grade1 grade0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys attain") keep(arm20)

	* Household poverty *
	
	use "$output/data_rw.dta", clear
	
	* poor kids
	rwolf enrol1 days_attend1 grade1 if poor_r10 ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum enrol1 if arm20==1 & poor_r10==1 
	local MmathTg=r(mean)
	sum enrol1 if arm20==0 & poor_r10==1 
	local MmathCg=r(mean)
	sum enrol1 if arm20==1 & poor_r10==0 
	local MmathTb=r(mean)
	sum enrol1 if arm20==0 & poor_r10==0 
	local MmathCb=r(mean)
	
	sum days_attend1 if arm20==1 & poor_r10==1 
	local MlitTg=r(mean)
	sum days_attend1 if arm20==0 & poor_r10==1 
	local MlitCg=r(mean)
	sum days_attend1 if arm20==1 & poor_r10==0 
	local MlitTb=r(mean)
	sum days_attend1 if arm20==0 & poor_r10==0 
	local MlitCb=r(mean)
	
	sum grade1 if arm20==1 & poor_r10==1 
	local MlearnTg=r(mean)
	sum grade1 if arm20==0 & poor_r10==1 
	local MlearnCg=r(mean)
	sum grade1 if arm20==1 & poor_r10==0 
	local MlearnTb=r(mean)
	sum grade1 if arm20==0 & poor_r10==0 
	local MlearnCb=r(mean)
	
	local rw_enr_poor=e(rw_enrol1)
	local rw_att_poor=e(rw_days_attend1)
	local rw_gr_poor=e(rw_grade1)
	
	* Non-poor
	rwolf enrol1 days_attend1 grade1 if poor_r10 ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_enr_nonpoor=e(rw_enrol1)
	local rw_att_nonpoor=e(rw_days_attend1)
	local rw_gr_nonpoor=e(rw_grade1)
		
	local doit "replace"
	local doit2 "append"
	
	* Enrolment *
	
	reg enrol1 enrol0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("Poor enrol") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_enr_poor') keep(arm20)
	
	reg enrol1 enrol0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor enrol") keep(arm20)
	
	reg enrol1 enrol0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor enrol") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_enr_nonpoor') keep(arm20)
		
	reg enrol1 enrol0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor enrol") keep(arm20)
	
	* Attendance * 
	
	reg days_attend1 days_attend0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor attendance") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_att_poor') keep(arm20)
	
	reg days_attend1 days_attend0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor att") keep(arm20)
	
	reg days_attend1 days_attend0  arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor att") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_att_nonpoor') keep(arm20)
		
	reg days_attend1 days_attend0  arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor lit") keep(arm20)
	
	* Attainment *
	
	reg grade1 grade0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor attain") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg', R-W p-value, `rw_gr_poor' ) keep(arm20)
	
	reg grade1 grade0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor attain") keep(arm20)
		
	reg grade1 grade0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Nonpoor attain") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb', R-W p-value, `rw_gr_nonpoor' ) keep(arm20) 
		
	reg grade1 grade0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor attain") keep(arm20)

	* Geography *
	
	use "$output/data_rw.dta", clear
	
	* north
	rwolf enrol1 days_attend1 grade1 if north1 ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum enrol1 if arm20==1 & north1==1 
	local MmathTg=r(mean)
	sum enrol1 if arm20==0 & north1==1 
	local MmathCg=r(mean)
	sum enrol1 if arm20==1 & north1==0 
	local MmathTb=r(mean)
	sum enrol1 if arm20==0 &  north1==0 
	local MmathCb=r(mean)
	
	sum days_attend1 if arm20==1 & north1==1 
	local MlitTg=r(mean)
	sum days_attend1 if arm20==0 & north1==1 
	local MlitCg=r(mean)
	sum days_attend1 if arm20==1 & north1==0 
	local MlitTb=r(mean)
	sum days_attend1 if arm20==0 & north1==0 
	local MlitCb=r(mean)
	
	sum grade1 if arm20==1 & north1==1 
	local MlearnTg=r(mean)
	sum grade1 if arm20==0 & north1==1 
	local MlearnCg=r(mean)
	sum grade1 if arm20==1 & north1==0 
	local MlearnTb=r(mean)
	sum grade1 if arm20==0 & north1==0 
	local MlearnCb=r(mean)
	
	local rw_enr_north=e(rw_enrol1)
	local rw_att_north=e(rw_days_attend1)
	local rw_gr_north=e(rw_grade1)
	
	* boys
	rwolf enrol1 days_attend1 grade1 if north1 ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_enr_south=e(rw_enrol1)
	local rw_att_south=e(rw_days_attend1)
	local rw_gr_south=e(rw_grade1)
		
	local doit "replace"
	local doit2 "append"
	
	* Enrolment *
	
	reg enrol1 enrol0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("North enrol") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_enr_north') keep(arm20)
	
	reg enrol1 enrol0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North enrol") keep(arm20)
	
	reg enrol1 enrol0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South enrol") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_enr_south') keep(arm20)
		
	reg enrol1 enrol0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South enrol") keep(arm20)
	
	* Attendance * 
	
	reg days_attend1 days_attend0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North attendance") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_att_north') keep(arm20)
	
	reg days_attend1 days_attend0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North att") keep(arm20)
	
	reg days_attend1 days_attend0  arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("South att") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_att_south') keep(arm20)
		
	reg days_attend1 days_attend0  arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South lit") keep(arm20)
	
	* Attainment *
	
	reg grade1 grade0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North attain") ///
	addstat(Mean Treatment, `MlearnTg', Mean Control, `MlearnCg', R-W p-value, `rw_gr_north' ) keep(arm20)
	
	reg grade1 grade0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North attain") keep(arm20)
		
	reg grade1 grade0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("South attain") ///
	addstat(Mean Treatment, `MlearnTb', Mean Control, `MlearnCb', R-W p-value, `rw_gr_south' ) keep(arm20) 
		
	reg grade1 grade0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("South attain") keep(arm20)

	*** COGNITION ***
	
	rwolf zdigit1 zraven1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 

	local doit "replace"
	local doit2 "append"
	
	sum zdigit1 if arm20==1 
	local MenrT=r(mean)
	sum zdigit1 if arm20==0 
	local MenrC=r(mean)
	
	sum zraven1 if arm20==1 
	local MdayT=r(mean)
	sum zraven1 if arm20==0 
	local MdayC=r(mean)
	
	sum cog_ind1 if arm20==1 
	local MgrT=r(mean)
	sum cog_ind1 if arm20==0 
	local MgrC=r(mean)
	
	local rw_enr=e(rw_zdigit1)
	local rw_day=e(rw_zraven1)

	reg zdigit1 zdigit0 arm20 i.region0, vce(cluster locid) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast dec(3) bdec(3) ///
	addstat(Mean Treatment, `MenrT', Mean Control, `MenrC', R-W p-value, `rw_enr') ctitle("Digit") keep(arm20)
	
	reg zdigit1 zdigit0 arm20 i.region0 , vce(cluster locid) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Digit") keep(arm20)
			
	reg zraven1 zraven0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast   dec(3) bdec(3) addstat(Mean Treatment, `MdayT', Mean Control, `MdayC', ///
	R-W p-value, `rw_day') ctitle("Raven") keep(arm20)
	
	reg zraven1 zraven0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("Raven") keep(arm20)

	reg cog_ind1 cog_ind0 arm20 i.region0  , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  dec(3) bdec(3) ///
	addstat(Mean Treatment, `MgrT', Mean Control, `MgrC') ctitle("composite") keep(arm20)
		
	reg cog_ind1 cog_ind0 arm20 i.region0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket  dec(3) bdec(3) ctitle("composite") keep(arm20)
	
	* Gender *
	
	use "$output/data_rw.dta", clear
	
	* gen girl dummy
	gen girl=1 if male1==0
		replace girl =0 if male1==1

	* girls
	rwolf zdigit1 zraven1 if girl ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum zdigit1 if arm20==1 & girl==1 
	local MmathTg=r(mean)
	sum zdigit1 if arm20==0 & girl==1 
	local MmathCg=r(mean)
	sum zdigit1 if arm20==1 & girl==0 
	local MmathTb=r(mean)
	sum zdigit1 if arm20==0 & girl==0 
	local MmathCb=r(mean)
	
	sum zraven1 if arm20==1 & girl==1 
	local MlitTg=r(mean)
	sum zraven1 if arm20==0 & girl==1 
	local MlitCg=r(mean)
	sum zraven1 if arm20==1 & girl==0 
	local MlitTb=r(mean)
	sum zraven1 if arm20==0 & girl==0 
	local MlitCb=r(mean)
	
	sum cog_ind1 if arm20==1 & girl==1 
	local McogTg=r(mean)
	sum cog_ind1 if arm20==0 & girl==1 
	local McogCg=r(mean)
	sum cog_ind1 if arm20==1 & girl==0 
	local McogTb=r(mean)
	sum cog_ind1 if arm20==0 & girl==0 
	local McogCb=r(mean)
	
	local rw_enr_girl=e(rw_zdigit1)
	local rw_att_girl=e(rw_zraven1)
	
	* boys
	rwolf zdigit1 zraven1 if girl ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_enr_boy=e(rw_zdigit1)
	local rw_att_boy=e(rw_zraven1)
		
	local doit "replace"
	local doit2 "append"
	
	* Digit *
	
	reg zdigit1 zdigit0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("Girls digit") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_enr_girl') keep(arm20)
	
	reg zdigit1 zdigit0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls digit") keep(arm20)
	
	reg zdigit1 zdigit0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Boys digit") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_enr_boy') keep(arm20)
		
	reg zdigit1 zdigit0 arm20 i.region0 if girl ==0 , vce(cluster region) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys digit") keep(arm20)
	
	* Raven * 
	
	reg zraven1 zraven0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Girls raven") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_att_girl') keep(arm20)
	
	reg zraven1 zraven0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls raven") keep(arm20)
	
	reg zraven1 zraven0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Boys raven") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_att_boy') keep(arm20)
		
	reg zraven1 zraven0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys raven") keep(arm20)
	
	* Cogs *
	
	reg cog_ind1 cog_ind0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Girls cogs") ///
	addstat(Mean Treatment, `McogTg', Mean Control, `McogCg') keep(arm20)
	
	reg cog_ind1 cog_ind0 arm20 i.region0 if girl ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Girls cogs") keep(arm20)
		
	reg cog_ind1 cog_ind0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Boys cogs") ///
	addstat(Mean Treatment, `McogTb', Mean Control, `McogCb' ) keep(arm20) 
		
	reg cog_ind1 cog_ind0 arm20 i.region0 if girl ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Boys cogs") keep(arm20)

	* Household Poverty *
	
	use "$output/data_rw.dta", clear

	* Poor
	rwolf zdigit1 zraven1 if poor_r10 ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum zdigit1 if arm20==1 & poor_r10==1 
	local MmathTg=r(mean)
	sum zdigit1 if arm20==0 & poor_r10==1 
	local MmathCg=r(mean)
	sum zdigit1 if arm20==1 & poor_r10==0 
	local MmathTb=r(mean)
	sum zdigit1 if arm20==0 & poor_r10==0 
	local MmathCb=r(mean)
	
	sum zraven1 if arm20==1 & poor_r10==1 
	local MlitTg=r(mean)
	sum zraven1 if arm20==0 & poor_r10==1 
	local MlitCg=r(mean)
	sum zraven1 if arm20==1 & poor_r10==0 
	local MlitTb=r(mean)
	sum zraven1 if arm20==0 & poor_r10==0 
	local MlitCb=r(mean)
	
	sum cog_ind1 if arm20==1 & poor_r10==1 
	local McogTg=r(mean)
	sum cog_ind1 if arm20==0 & poor_r10==1 
	local McogCg=r(mean)
	sum cog_ind1 if arm20==1 & poor_r10==0 
	local McogTb=r(mean)
	sum cog_ind1 if arm20==0 & poor_r10==0 
	local McogCb=r(mean)
	
	local rw_enr_girl=e(rw_zdigit1)
	local rw_att_girl=e(rw_zraven1)
	
	* Non poor
	rwolf zdigit1 zraven1 if poor_r10 ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_enr_boy=e(rw_zdigit1)
	local rw_att_boy=e(rw_zraven1)
		
	local doit "replace"
	local doit2 "append"
	
	* Digit *
	
	reg zdigit1 zdigit0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("Poor digit") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_enr_girl') keep(arm20)
	
	reg zdigit1 zdigit0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor digit") keep(arm20)
	
	reg zdigit1 zdigit0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor digit") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_enr_boy') keep(arm20)
		
	reg zdigit1 zdigit0 arm20 i.region0 if poor_r10 ==0 , vce(cluster region) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor digit") keep(arm20)
	
	* Raven * 
	
	reg zraven1 zraven0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor raven") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_att_girl') keep(arm20)
	
	reg zraven1 zraven0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Poor raven") keep(arm20)
	
	reg zraven1 zraven0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("Nonpoor raven") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_att_boy') keep(arm20)
		
	reg zraven1 zraven0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor raven") keep(arm20)
	
	* Cogs *
	
	reg cog_ind1 cog_ind0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Poor cogs") ///
	addstat(Mean Treatment, `McogTg', Mean Control, `McogCg') keep(arm20)
	
	reg cog_ind1 cog_ind0 arm20 i.region0 if poor_r10 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("nonpoor cogs") keep(arm20)
		
	reg cog_ind1 cog_ind0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("Nonpoor cogs") ///
	addstat(Mean Treatment, `McogTb', Mean Control, `McogCb' ) keep(arm20) 
		
	reg cog_ind1 cog_ind0 arm20 i.region0 if poor_r10 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("Nonpoor cogs") keep(arm20)

	* Geography *
	
	use "$output/data_rw.dta", clear

	* North
	rwolf zdigit1 zraven1 if north1 ==1, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	
	sum zdigit1 if arm20==1 & north1==1 
	local MmathTg=r(mean)
	sum zdigit1 if arm20==0 & north1==1 
	local MmathCg=r(mean)
	sum zdigit1 if arm20==1 & north1==0 
	local MmathTb=r(mean)
	sum zdigit1 if arm20==0 & north1==0 
	local MmathCb=r(mean)
	
	sum zraven1 if arm20==1 & north1==1 
	local MlitTg=r(mean)
	sum zraven1 if arm20==0 & north1==1 
	local MlitCg=r(mean)
	sum zraven1 if arm20==1 & north1==0 
	local MlitTb=r(mean)
	sum zraven1 if arm20==0 & north1==0 
	local MlitCb=r(mean)
	
	sum cog_ind1 if arm20==1 & north1==1 
	local McogTg=r(mean)
	sum cog_ind1 if arm20==0 & north1==1 
	local McogCg=r(mean)
	sum cog_ind1 if arm20==1 & north1==0 
	local McogTb=r(mean)
	sum cog_ind1 if arm20==0 & north1==0 
	local McogCb=r(mean)
	
	local rw_enr_girl=e(rw_zdigit1)
	local rw_att_girl=e(rw_zraven1)
	
	* South
	rwolf zdigit1 zraven1 if north1 ==0, indepvar(arm20) controls(i.region0 baseline) seed(7) reps(2000) vce(cluster locid0) 
	local rw_enr_boy=e(rw_zdigit1)
	local rw_att_boy=e(rw_zraven1)
		
	local doit "replace"
	local doit2 "append"
	
	* Digit *
	
	reg zdigit1 zdigit0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit' pvalue bracket noast ctitle("North digit") ///
	addstat(Mean Treatment, `MmathTg', Mean Control, `MmathCg', R-W p-value, `rw_enr_girl') keep(arm20)
	
	reg zdigit1 zdigit0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North digit") keep(arm20)
	
	reg zdigit1 zdigit0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("S digit") ///
	addstat(Mean Treatment, `MmathTb', Mean Control, `MmathCb', R-W p-value, `rw_enr_boy') keep(arm20)
		
	reg zdigit1 zdigit0 arm20 i.region0 if north1 ==0 , vce(cluster region) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("S digit") keep(arm20)
	
	* Raven * 
	
	reg zraven1 zraven0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North raven") ///
	addstat(Mean Treatment, `MlitTg', Mean Control, `MlitCg', R-W p-value, `rw_att_girl') keep(arm20)
	
	reg zraven1 zraven0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North raven") keep(arm20)
	
	reg zraven1 zraven0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast  ctitle("S raven") ///
	addstat(Mean Treatment, `MlitTb', Mean Control, `MlitCb', R-W p-value, `rw_att_boy') keep(arm20)
		
	reg zraven1 zraven0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("S raven") keep(arm20)
	
	* Cogs *
	
	reg cog_ind1 cog_ind0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("North cogs") ///
	addstat(Mean Treatment, `McogTg', Mean Control, `McogCg') keep(arm20)
	
	reg cog_ind1 cog_ind0 arm20 i.region0 if north1 ==1 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("North cogs") keep(arm20)
		
	reg cog_ind1 cog_ind0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' pvalue bracket noast ctitle("S cogs") ///
	addstat(Mean Treatment, `McogTb', Mean Control, `McogCb' ) keep(arm20) 
		
	reg cog_ind1 cog_ind0 arm20 i.region0 if north1 ==0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, `doit2' ci bracket ctitle("S cogs") keep(arm20)

	******************* interaction models (as i report the p-values of the interactions in the text) ***************
	* [Note: for the full code please refer to dofile "analysis_sept24_2019, lines 203-416]
	
	* gender
	use "$output/data_rw.dta", clear
	
	gen girl=1 if male1==0
		replace girl =0 if male1==1
	
	gen girl_sf =girl*arm20 

	rwolf zmaths1 zlit1, indepvar(girl_sf) controls(i.region0 baseline arm20 girl) seed(7) reps(2000) vce(cluster locid0) 

	reg zmaths1 zmaths0 girl arm20 girl_sf i.region0  , vce(cluster locid0) 
	reg zlit1 zlit0 girl arm20 girl_sf i.region0  , vce(cluster locid0) 
	reg learn_ind1 learn_ind0 girl arm20 girl_sf i.region0  , vce(cluster locid0) 

	* Poverty
	
	use "$output/data_rw.dta", clear
	
	gen poor_sf =poor_r10*arm20 

	rwolf zmaths1 zlit1, indepvar(poor_sf) controls(i.region0 baseline arm20 poor_r10) seed(7) reps(2000) vce(cluster locid0) 

	reg zmaths1 zmaths0 poor_r10 arm20 poor_sf i.region0  , vce(cluster locid0) 
	reg zlit1 zlit0 poor_r10 arm20 poor_sf i.region0  , vce(cluster locid0) 
	reg learn_ind1 learn_ind0 poor_r10 arm20 poor_sf i.region0  , vce(cluster locid0) 
	
	* Northern regions
	
	use "$output/data_rw.dta", clear

	gen north_sf =north1*arm20 
	
	rwolf zmaths1 zlit1, indepvar(north_sf) controls(i.region0 baseline arm20 north1) seed(7) reps(2000) vce(cluster locid0) 

	reg zmaths1 zmaths0 north1 arm20 north_sf i.region0  , vce(cluster locid0) 
	reg zlit1 zlit0 north1 arm20 north_sf i.region0  , vce(cluster locid0) 
	reg learn_ind1 learn_ind0 north1 arm20 north_sf i.region0  , vce(cluster locid0) 

	************ MARCH 2020: CHECK HETEROGENEITY BY EXPOSURE
	
	use "$output/combined_data.dta", clear
	
	drop if child_panel ==0
	keep u_id child_panel zmaths zlit learn_ind arm2 wave region locid age_r1 grade male 
		
	reshape wide child_panel zmaths zlit learn_ind arm2 region locid age_r1 grade male, i(u_id) j(wave)
	
	gen exp =age_r10 <=5
		replace exp=1 if age_r10 ==10 & grade0 == 5 | age_r10 ==11 & grade0==5
	
	gen exp =age_r10 <=5
			replace exp=1 if grade0 == 5 
			
	gen exp2y=exp==0		


	reg zmaths1 zmaths0 arm20 i.region0 if exp2y==1, vce(cluster locid0) 
	outreg2 using rank_m.xls, replace ctitle("Maths 2 years of exposure") keep(arm20)
	
	reg zlit1 zlit0 arm20 i.region0  if exp2y==1, vce(cluster locid0) 
	outreg2 using rank_m.xls, append ctitle("Lit 2 years of exposure") keep(arm20)
	
	reg learn_ind1 learn_ind0 arm20 i.region0 if exp2y==1, vce(cluster locid0) 
	outreg2 using rank_m.xls, append ctitle("Composite: 2 years") keep(arm20)
	
	reg zmaths1 zmaths0 arm20 i.region0 if exp2y==0, vce(cluster locid0) 
	outreg2 using rank_m.xls, append ctitle("Maths 1 years of exposure") keep(arm20)
	
	reg zlit1 zlit0 arm20 i.region0  if exp2y==0, vce(cluster locid0) 
	outreg2 using rank_m.xls, append ctitle("Lit 1 years of exposure") keep(arm20)
	
	reg learn_ind1 learn_ind0 arm20 i.region0 if exp2y==0, vce(cluster locid0) 
	outreg2 using rank_m.xls, ctitle("Composite: 1 years") keep(arm20) append
	
	
	preserve
	keep if male0==0
	reg zmaths1 zmaths0 arm20##exp2y i.region0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, replace ctitle("Maths 2 years of exposure") 
	reg zlit1 zmaths0 arm20##exp2y i.region0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, append ctitle("Maths 2 years of exposure") 
	reg learn_ind1 zmaths0 arm20##exp2y i.region0 , vce(cluster locid0) 
	outreg2 using rank_m.xls, append ctitle("Maths 2 years of exposure") 
	restore
	
	
	**** ROBUSTNESS
	
	gen inter=0 if arm2!=. & wave!=. 
		replace inter=1 if wave==1 & arm2==1
	
	teffects ipw (zmaths) (child_panel inter wave north#arm2, probit)

	
	
	
